<div class="grid fieldscontainer">
<h3><?php echo $title?></h3>
<?php echo  form_open(get_currcontroller()."/run/go", array('id'=>'run_'.$orid, 'autocomplete'=>'off'))?>
<div class="container editform">
<?php if(validation_errors()){?>
<div class="error">
	<?php echo validation_errors('<div>', '</div>');?>
</div>	
<?php }?>
<div class="column span-3">
	<?php echo form_label(lang('DATE_REPORT_FROM').required_field(), 'date_report_from')?>
</div>
<div class="column span-21">
	<?php echo form_input('date_report_from', set_value('date_report_from', ''), 'id="date_report_from" class="text date-entry"')?>
	<script type="text/javascript">
		$('#date_report_from').dateEntry({dateFormat: '<?php echo $this->config->item('crm_date_entry_format')?>', spinnerImage:''});
	</script>
</div>
<div class="column span-3">
	<?php echo form_label(lang('DATE_REPORT_TO').required_field(), 'date_report_to')?>
</div>
<div class="column span-21">
	<?php echo form_input('date_report_to', set_value('date_report_to', ''), 'id="date_report_to" class="text date-entry"')?>
	<script type="text/javascript">
		$('#date_report_to').dateEntry({dateFormat: '<?php echo $this->config->item('crm_date_entry_format')?>', spinnerImage:''});	
	</script>
</div>
<div class="column span-3">
	<?php echo form_label(lang('ADV_COMPANY'), 'company_name')?>
</div>
<div class="column span-21 last">
	<?php echo get_advertisescompanies_vp(set_value('_advertisescompanies_rid', ''))?>
</div>

</div>
<div class="column span-24 last controls">
	<input type="submit" value="<?php echo lang('SAVE')?>" class="button" id="submit" name="submit"> <input type="reset" value="<?php echo lang('CANCEL')?>" class="button" onclick="window.location='<?php echo site_url(get_currcontroller()) ?>';" id="reset" name="reset">
</div>

<?php echo  form_close(); ?>
</div>
<?php  if(isset($ds) && $ds) { $num = 1; $total_cost = 0; $total_calls = 0; $total_demands = 0; $total_doxod = 0;?>
<div class="container" style="margin-top: 20px;">
<h5><?php echo $r_body_title?></h5>
	<table>
		<thead>
			<tr>
				<th>
					#
				</th>
				<th>
					<?php echo lang('ADV_NAME')?>
				</th>
				<th>
					<?php echo lang('ADV_TYPE')?>
				</th>
				<th>
					<?php echo lang('ADV_COST')?>
				</th>
				<th>
					<?php echo lang('ADV_CALLS_QUAN')?>
				</th>
				<th>
					<?php echo lang('ADV_DEMANDS_QUAN')?>
				</th>
				<th>
					<?php echo lang('ADV_CONVERSION')?>,%
				</th>
				<th>
					<?php echo lang('ADV_DOXOD')?>
				</th>
			</tr>
		</thead>
		<?php foreach($ds as $r) { $total_cost += $r['cost']; $total_calls += $r['calls_quan']; $total_demands += $r['demands_quan']; $total_doxod += $r['doxod'];?>
		<tr>
			<td>
				<?php echo $num?>
			</td>
			<td>
				<?php echo $r['adv_source_name']?>
			</td>
			<td>
				<?php echo $r['adv_type_name']?>
			</td>
			<td>
				<?php echo $r['cost']?>
			</td>
			<td>
				<?php echo $r['calls_quan']?>
			</td>
			<td>
				<?php echo $r['demands_quan']?>
			</td>
			<td>
				<?php echo intval($r['calls_quan'])?(ROUND(intval($r['demands_quan'])/intval($r['calls_quan']), 2)*100):0?>
			</td>
			<td>
				<?php echo $r['doxod']?>
			</td>
		</tr>
		<?php  $num++; } ?>
		<tr>
			<td colspan="3">	
				&nbsp;
			</td>
			<td style="font-weight: bold; background-color: #CCCCCC;">	
				<?php echo $total_cost?>
			</td>
			<td style="font-weight: bold; background-color: #CCCCCC;">
				<?php echo $total_calls?>
			</td>
			<td style="font-weight: bold; background-color: #CCCCCC;">
				<?php echo $total_demands?>
			</td>
			<td style="font-weight: bold; background-color: #CCCCCC;">
				<?php echo $total_calls?(ROUND(intval($total_demands)/intval($total_calls), 2)):0?>
			</td>
			<td style="font-weight: bold; background-color: #CCCCCC;">
				<?php echo $total_doxod?>
			</td>
		</tr>
	</table>	
</div>
<?php  } ?>
